// To get the local IP address in Node.js, we can use the built-in 'os' module
const os = require('os');

module.exports = {
    /**
     * 获取IP信息
     */
    getIpInfo() {
        // Get the network interfaces of the current machine
        const networkInterfaces = os.networkInterfaces();
        // Loop through the network interfaces and find the one that is not internal (i.e. not 127.0.0.1)
        let localIpAddress;
        Object.keys(networkInterfaces).forEach((interfaceName) => {
            const interface = networkInterfaces[interfaceName];
            interface.forEach((interfaceDetail) => {
                if (interfaceDetail.family === 'IPv4' && !interfaceDetail.internal) {
                    localIpAddress = interfaceDetail.address;
                }
            });
        });
        // The local IP address is now stored in the 'localIpAddress' variable
        return localIpAddress
    }
}